from django.contrib.auth.models import AbstractUser
from django.db import models
from django.utils.translation import gettext_lazy as _

class User(AbstractUser):
    ROLE_CHOICES = [
        ('manager', _('Руководитель')),
        ('hr', _('Кадровая служба')),
        ('radiologist', _('Врач-рентгенолог'))
    ]
    role = models.CharField(max_length=20, choices=ROLE_CHOICES)

    class Meta:
        verbose_name = _('Пользователь')
        verbose_name_plural = _('Пользователи')

class Radiologist(models.Model):
    first_name = models.CharField(max_length=50, verbose_name=_('Имя'))
    last_name = models.CharField(max_length=50, verbose_name=_('Фамилия'))
    middle_name = models.CharField(max_length=50, null=True, blank=True, verbose_name=_('Отчество'))
    modality = models.CharField(max_length=50, verbose_name=_('Модальность'))
    additional_modalities = models.CharField(max_length=200, blank=True, null=True, verbose_name=_('Дополнительные модальности'))
    position = models.CharField(max_length=50, verbose_name=_('Должность'))
    rate = models.FloatField(verbose_name=_('Ставка'))
    tab_number = models.CharField(max_length=20, verbose_name=_('Табельный номер'))
    working_hours = models.IntegerField(verbose_name=_('Рабочие часы'))
    full_month_hours = models.IntegerField(verbose_name=_('Полные месячные часы'))

    class Meta:
        verbose_name = _('Врач-рентгенолог')
        verbose_name_plural = _('Врачи-рентгенологи')

class Schedule(models.Model):
    radiologist = models.ForeignKey(Radiologist, on_delete=models.CASCADE, verbose_name=_('Врач-рентгенолог'))
    date = models.DateField(verbose_name=_('Дата'))
    shift_start = models.TimeField(verbose_name=_('Начало смены'))
    shift_end = models.TimeField(verbose_name=_('Конец смены'))
    break_duration = models.IntegerField(verbose_name=_('Продолжительность перерыва'))
    worked_hours = models.DecimalField(max_digits=4, decimal_places=1, verbose_name=_('Отработанные часы'))
    is_approved = models.BooleanField(default=False, verbose_name=_('Одобрено'))

    class Meta:
        verbose_name = _('Расписание')
        verbose_name_plural = _('Расписания')

class Leave(models.Model):
    LEAVE_TYPE_CHOICES = [
        ('vacation', _('Отпуск')),
        ('sick', _('Больничный'))
    ]
    radiologist = models.ForeignKey(Radiologist, on_delete=models.CASCADE, verbose_name=_('Врач-рентгенолог'))
    leave_type = models.CharField(max_length=20, choices=LEAVE_TYPE_CHOICES, verbose_name=_('Тип отпуска'))
    start_date = models.DateField(verbose_name=_('Дата начала'))
    end_date = models.DateField(verbose_name=_('Дата окончания'))

    class Meta:
        verbose_name = _('Отпуск')
        verbose_name_plural = _('Отпуска')

class UnforeseenCircumstance(models.Model):
    radiologist = models.ForeignKey(Radiologist, on_delete=models.CASCADE, verbose_name=_('Врач-рентгенолог'))
    date = models.DateField(verbose_name=_('Дата'))
    reason = models.CharField(max_length=200, verbose_name=_('Причина'))

    class Meta:
        verbose_name = _('Непредвиденное обстоятельство')
        verbose_name_plural = _('Непредвиденные обстоятельства')

class Study(models.Model):
    year = models.IntegerField(verbose_name=_('Год'))
    week_number = models.IntegerField(verbose_name=_('Номер недели'))
    modality = models.CharField(max_length=50, verbose_name=_('Модальность'))
    quantity = models.IntegerField(verbose_name=_('Количество'))
    ue_per_study = models.FloatField(verbose_name=_('УЕ за исследование'))
    is_with_contrast = models.BooleanField(default=False, verbose_name=_('С контрастом'))
    is_multiple_zones = models.BooleanField(default=False, verbose_name=_('Множественные зоны'))

    class Meta:
        verbose_name = _('Исследование')
        verbose_name_plural = _('Исследования')

class Workload(models.Model):
    year = models.IntegerField(verbose_name=_('Год'))
    week_number = models.IntegerField(verbose_name=_('Номер недели'))
    modality = models.CharField(max_length=50, verbose_name=_('Модальность'))
    predicted_quantity = models.IntegerField(verbose_name=_('Прогнозируемое количество'))
    actual_quantity = models.IntegerField(null=True, blank=True, verbose_name=_('Фактическое количество'))
    predicted_ue = models.FloatField(verbose_name=_('Прогнозируемые УЕ'))
    actual_ue = models.FloatField(null=True, blank=True, verbose_name=_('Фактические УЕ'))

    class Meta:
        verbose_name = _('Нагрузка')
        verbose_name_plural = _('Нагрузки')    